JS 上 call, aplly, bind 差異


Posted by YongChenSu on 2020-12-08

三者差異

  • call、apply皆是回傳 function 執行結果
  • bind方法回傳的是綁定 this 後的原函數

call 以及 aplly 的差異

call 接受一連串的參數,而 apply 接受一組陣列形式的參數。

效能上 call 優於 apply

在不确定参数的情况下,如果不考虑性能,代码层面用apply来写会简洁很多。不过你能确认参数长度的时候,最好都用call方法而不用apply。

參考資源


#程式導師實驗計畫第四期 #前端







Related Posts

The Wonders of Watchessy: Navigating the Maze of Mechanical Mastery

The Wonders of Watchessy: Navigating the Maze of Mechanical Mastery

234. Palindrome Linked List

234. Palindrome Linked List

1731. The Number of Employees Which Report to Each Employee

1731. The Number of Employees Which Report to Each Employee


Comments